cmake_minimum_required(VERSION 2.6)

PROJECT (SURFGPU)

INCLUDE(${CMAKE_SOURCE_DIR}/CMake/cuda/FindCUDA.cmake)
find_package(OpenCV REQUIRED)

#set(CUDA_BUILD_CUBIN ON)
set(CUDA_BUILD_EMULATION OFF)
set(CUDA_NVCC_FLAGS "-arch=sm_12")

option(CUDA_24BIT_IMUL "Use 24bit integer multiplication for IMUL macros" ON)
if(CUDA_24BIT_IMUL)
	add_definitions(-DCUDA_24BIT_IMUL)
endif()

option(SURF_MATCH_SIMPLE "Use simple SURF descriptor matching" OFF)
if(SURF_MATCH_SIMPLE)
	add_definitions(-DSURF_MATCH_SIMPLE)
endif()

# Needed for M_PI and friends on Windows
if(WIN32)
	add_definitions(-D_USE_MATH_DEFINES)
endif()

INCLUDE_DIRECTORIES(
${CMAKE_SOURCE_DIR}
${CUDA_TOOLKIT_INCLUDE}
${CUDA_CUT_INCLUDE_DIR}
${OpenCV_INCLUDE_DIR}
${CUDA_INCLUDE_DIRS}
)

CUDA_INCLUDE_DIRECTORIES(
${CMAKE_SOURCE_DIR}
${CUDA_TOOLKIT_INCLUDE}
${CUDA_CUT_INCLUDE_DIR}
${OpenCV_INCLUDE_DIR}
${CUDA_INCLUDE_DIRS}
)

# Add directory where CUDPP resides
set(CUDA_SDK_LIB_DIR "${CUDA_SDK_ROOT_DIR}/common/lib")
# CUDA SDK lib dir includes OS name on Linux (as of CUDA SDK v2.2)
if(NOT WIN32)
	string(TOLOWER ${CMAKE_SYSTEM_NAME} OS)
	set(CUDA_SDK_LIB_DIR "${CUDA_SDK_LIB_DIR}/${OS}")
endif()
LINK_DIRECTORIES(
	${CUDA_SDK_LIB_DIR}
)

CUDA_ADD_EXECUTABLE(surf
	fasthessian.cpp
	helper_funcs.cpp
	integral.cpp
	ipoint.cpp
	main.cpp
	surf.cpp
	utils.cpp
	cuda/buildSURFDescriptorsGPU.cu
	cuda/convertRGB2GrayFloatGPU.cu
	cuda/detectIpointOrientationsGPU.cu
	cuda/getMatchesGPU.cpp
	cuda/buildDetGPU.cu
	cuda/nonMaxGPU.cu
	cuda/matchSURFKeypointsGPU.cu
	cuda/normalizeSURFDescriptorsGPU.cu
	cuda/transposeGPU.cu
)

# Determine cudpp library name to use on this system
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
	set(CUDA_CUDPP_BUILD_TYPE_SUFFIX "D")
else()
	set(CUDA_CUDPP_BUILD_TYPE_SUFFIX "")
endif()

if(CMAKE_SIZEOF_VOID_P EQUAL 4)
	if(WIN32)
		set(CUDA_CUDPP_BITNESS_SUFFIX "32")
	else()
		set(CUDA_CUDPP_BITNESS_SUFFIX "")
	endif()
else()
	set(CUDA_CUDPP_BITNESS_SUFFIX "64")
endif()

if(CUDA_BUILD_EMULATION)
	set(CUDA_CUDPP_CUDA_BUILD_SUFFIX "_emu")
else()
	set(CUDA_CUDPP_CUDA_BUILD_SUFFIX "")
endif()

set(CUDA_CUDPP_LIBRARY "cudpp${CUDA_CUDPP_BITNESS_SUFFIX}")
set(CUDA_CUDPP_LIBRARY "${CUDA_CUDPP_LIBRARY}${CUDA_CUDPP_BUILD_TYPE_SUFFIX}")
set(CUDA_CUDPP_LIBRARY "${CUDA_CUDPP_LIBRARY}${CUDA_CUDPP_CUDA_BUILD_SUFFIX}")


TARGET_LINK_LIBRARIES(surf
${CUDA_LIBRARIES}
${OpenCV_LIBS}
${CUDA_CUDA_LIBRARY}
${CUDA_CUT_LIBRARY}
${CUDA_CUDART_LIBRARY}
${CUDA_CUDPP_LIBRARY}
)

